package com.arlin.spring.factory;

import com.arlin.spring.annotation.ioc.Controller;
import com.arlin.spring.annotation.aop.Aspect;
import com.arlin.spring.annotation.ioc.Component;
import com.arlin.spring.common.ReflectionUtil;

import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @ClassName: ClassFactory
 * @Description: TODO
 * @Author: arlin
 * @Date: 2021/12/11
 */
public class ClassFactory {

    /**
     * key是注解类
     * value是标注了该注解的class集合
     */
    public static final Map<Class<? extends Annotation>, Set<Class<?>>> CLASSES = new ConcurrentHashMap<>();

    /**
     * 对扫描路径上的类进行过滤分类
     * @param packageNames 扫描路径
     */
    public static void loadClass(String[] packageNames) {
        Set<Class<?>> restControllers = ReflectionUtil.scanAnnotatedClass(packageNames, Controller.class);
        Set<Class<?>> components = ReflectionUtil.scanAnnotatedClass(packageNames, Component.class);
        Set<Class<?>> aspects = ReflectionUtil.scanAnnotatedClass(packageNames, Aspect.class);
        CLASSES.put(Controller.class, restControllers);
        CLASSES.put(Component.class, components);
        CLASSES.put(Aspect.class, aspects);
    }

}
